﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using WindowsForms.AOnline.Presenter.Dictionary.Unit;
using WindowsForms.AOnline.View.Dictionary;
using WindowsForms.AOnline.WindowsForm.BaseUserControls;

namespace WindowsForms.AOnline.WindowsForm.UserControl.Dictionary
{
    public partial class UserControlUnitList : BaseTreeListUserControl, IUnitsView  
    {
        private readonly UnitsPresenter _unitsPresenter;   

        public UserControlUnitList()
        {
            InitializeComponent();
            _unitsPresenter = new UnitsPresenter(this);
        }

        /// <summary>
        /// Deletes the grid.
        /// </summary>
        protected override string DeleteTree()
        {
            return new UnitPresenter(null).Delete(int.Parse(PrimaryKeyValue));
        }

        /// <summary>
        /// Loads the data into grid.
        /// </summary>
        protected override void LoadDataIntoTree(int page) 
        {
            TotalPage = _unitsPresenter.GetPageSize();
            if (page <= TotalPage)
            {
                _unitsPresenter.Display(page);
            }
        }

        public IList<Model.BusinessObjects.Dictionary.UnitModel> Units
        {
            set { treeList.DataSource = value; }
        }

        private void treeList_NodeCellStyle(object sender, DevExpress.XtraTreeList.GetCustomNodeCellStyleEventArgs e)
        {
            //e.Appearance.Font = Convert.ToBoolean(e.Node["IsDetail"])
            //                     ? new Font(e.Appearance.Font.FontFamily, e.Appearance.Font.Size, FontStyle.Regular)
            //                     : new Font(e.Appearance.Font.FontFamily, e.Appearance.Font.Size, FontStyle.Bold);
        }
    }
}
